<!DOCTYPE html>
<html class="x-admin-sm">

<head>
	<meta charset="UTF-8">
	<title>电子学会比赛管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
	<link rel="stylesheet" href="./css/font.css">
	<link rel="stylesheet" href="./css/common.css">
	<link rel="stylesheet" href="./css/xadmin.css">
	<script src="./lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="./js/xadmin.js"></script>
	<script type="text/javascript" src="./js/abkj/auth/api/adminzoneview.js"></script>
	<script type="text/javascript" src="./js/abkj/auth/api/account.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/grade.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/zone.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/schedule.js"></script>

	<script type="text/javascript" src="./js/abkj/match/api/tmatch.js"></script>
	<script type="text/javascript" src="./js/abkj/match/api/team.js"></script>
	<script type="text/javascript" src="./js/abkj/auth/api/teamuserinfoview.js"></script>

	<script type="text/javascript" src="./js/abkj/match/api/signup.js"></script>
		<script type="text/javascript" src="./js/abkj/ext/login.js"></script>
	<script type="text/javascript" src="./js/abkj/ext/matchExt.js"></script>
	<script type="text/javascript" src="./js/abkj/fun_tool.js"></script>
	<script type="text/javascript" src="./js/abkj/slAjax.js"></script>
</head>

<body>
<div id="content">
	<div class="x-nav">
		<span class="layui-breadcrumb">
				<a href="">首页</a>
				<a><cite>比赛管理</cite></a>
				<a><cite>报名管理</cite></a>
		</span>
		<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
			<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
		</a>
	</div>
	<div class="layui-fluid">
		<div class="layui-row layui-col-space15">
			<div class="layui-col-md12">
				<div class="layui-card">
					<div class="layui-card-body">
						<form class="layui-form layui-col-space5 flex" style="display: flex; flex-wrap: wrap;" @submit.prevent>
							<!-- <div class="layui-input-inline layui-show-xs-block flex">
								<div class="mr5">参赛状态</div>
								<select name="matchStatus" lay-filter="matchStatusChange">
									<option value="">请选择</option>
									<option value="1">已参赛</option>
									<option value="2">未参赛</option>
									<!--<option v-for="match in matchList" :value="match.id">{{match.theme}}</option>-->
									<!-- <option>全部</option>
									<option>支付宝</option>
									<option>微信</option>
									<option>货到付款</option> -->
								<!-- </select>
							</div> -->
							<div class="layui-input-inline layui-show-xs-block flex">
								<div class="mr5">赛项</div>
								<select name="selMatchId" name="matchSelect" lay-filter="matchSelChange">
									<option value="">请选择</option>
									<option v-for="match in matchList" :value="match.id">{{match.theme}}</option>
									<!-- <option>全部</option>
									<option>支付宝</option>
									<option>微信</option>
									<option>货到付款</option> -->
								</select>
							</div>
							<div class="layui-input-inline layui-show-xs-block flex">
								<div class="mr5">赛区</div>
								<select name="selZoneId" name="zoneSelect" lay-filter="zoneSelChange">
									<option value="">请选择</option>
									<option v-for="zone in zoneList" :value="zone.id">{{zone.zoneName}}</option>
									<!-- <option value="">全部</option>
									<option value="0">待确认</option>
									<option value="1">已确认</option> -->
								</select>
							</div>
							<div class="layui-input-inline layui-show-xs-block flex">
								<div class="mr5">组别</div>
								<select name="selGradeId"name="gradeSelect" lay-filter="gradeSelChange" >
									<option value="">请选择</option>
									<option v-for="grade in gradeList" :value="grade.id">{{grade.gradeName}}</option>
									<!-- <option value="">全部</option>
									<option value="0">小学</option>
									<option value="1">初中</option>
									<option value="2">高中</option> -->
								</select>
							</div>
							<div class="layui-input-inline layui-show-xs-block flex">
								<div class="mr5">审核/参赛状态</div>
								<select name="selState" name="stateSelect" lay-filter="stateSelChange">
									<option value="">请选择</option>
									<option value="0">组队中</option>
									<option value="1">待审核</option>
									<option value="2">通过</option>
									<!-- <option value="3">弃权</option> -->
									<option value="4">不通过</option>
								</select>
							</div>
							<!-- <div class="layui-input-inline layui-show-xs-block flex">
								<div class="mr5">晋级状态</div>
								<select name="jinji" name="jinji" lay-filter="stateSelChange1">
									<option value="">请选择</option>
									<option v-for="saicheng in saichengList" :value="saicheng.scheduleName">{{saicheng.scheduleName}}</option>

								</select>
							</div> -->
							<div class="layui-input-inline layui-show-xs-block flex">
								<div class="mr5" style="width: 40px;">账号</div>
								<input type="text" name="number" placeholder="账号" autocomplete="off" class="layui-input"></div>
							<div class="layui-input-inline layui-show-xs-block">
								<button ref="search" class="layui-btn" lay-submit="" lay-filter="search">
									<i class="layui-icon">&#xe615;</i></button>
							</div>
						</form>
					</div>
					<div class="layui-card-body ">
						<div style="overflow-x: auto;" class="layui-form"  v-cloak>
							<table class="layui-table">
							<span>共计{{ signUpList.total }}条数据</span>
							<button class="layui-btn layui-btn-sm" onclick="daochu()">导出</button>
							<thead>
							<tr>
								<th v-for="item in cols">{{ item.title }}</th>
							</tr>
							</thead>
							<tbody>
							<tr v-for="item in list">
								<td>{{ item.id }}</td>
								<td>
									<a  href="javascript:;" v-on:click="review(item.userId,item.signupId,item.projectid,item.project,item.status)" style="color: #01AAED;" class="layui-table-link">审核</a>
									<!-- <a  href="javascript:;" v-on:click="delet1(item.signupId)" style="color: #01AAED;" class="layui-table-link">删除组队</a> -->
									<!-- <a v-if="item.status === 1" href="javascript:;" onclick="xadmin.open('审核','review.html',600,400)" style="color: #01AAED;" class="layui-table-link">审核</a> -->
									<a v-else href="javascript:;" style="color: #01AAED;" class="layui-table-link">{{participate[item.isEnter]}}</a>
								</td>
								<td>


									<span v-if="item.status  <2">审核中</span>
									<span v-else-if="item.status  ==  2">审核通过</span>
									<span v-else-if="item.status  ==  3">弃权</span>
									<span v-else-if="item.status  ==  4">审核不通过</span>
								</td>
								<td><span v-if="item.status==0">组队中</span>
                                    <span v-else-if="item.status>0">组队成功</span>
								</td>
								<td><a href="javascript:;" style="color: #01AAED;" v-on:click="showMemberList(item.signupId,item.saicheng,item.matchId)" class="layui-table-link">查看</a></td>
							
								<td>{{item.signupId}}</td>
								<td>{{ item.username }}</td>
								<td>{{ item.account }}</td>
								<td>{{ item.project }}</td>
								<td>{{ item.division }}</td>
								<td>{{ item.saicheng }}</td>
								<td>{{ item.group }}</td>
								<td>{{ item.teamName }}</td>
								<td>{{ item.teacher }}</td>
								<td>{{ item.school }}</td>
								<!-- <td>{{ item.player }}</td> -->
									<!-- <td><a href="javascript:;" style="color: #01AAED;" onclick="parent.xadmin.open('队员信息','playerInformation.html',600,600)" class="layui-table-link">查看</a></td> -->
							
								
								<td><a href="javascript:;"> {{ item.isEnter === 1  ? '弃权' : '参赛' }}</a></td>
							
								<!-- <td>{{ item.message }}</td> -->
							</tr>
							</tbody>
						</table>
						</div>
						<section id="test1"></section>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>


</body>
<script src="./js/vue.js"></script>
<script>
function daochu(){
	var prjName="mgr_"
	var url='https://serviceprod.kpcb.org.cn/abkj-api-match-provider/excel/exportExcelSign?Authorization='+localStorage.getItem(prjName+"token")
	var downloadLink = document.createElement('a');
					document.body.appendChild(downloadLink);

					// Use special ms version if available to get it working on Edge.

					downloadLink.href = url;
					downloadLink.target='_blank'
					// console.log(url)

					downloadLink.click();

					document.body.removeChild(downloadLink);
					window.URL.revokeObjectURL(myurl);
}
Date.prototype.Format = function(fmt)
	{ //author: meizz
		var o = {
			"M+" : this.getMonth()+1,                 //月份
			"d+" : this.getDate(),                    //日
			"h+" : this.getHours(),                   //小时
			"m+" : this.getMinutes(),                 //分
			"s+" : this.getSeconds(),                 //秒
			"q+" : Math.floor((this.getMonth()+3)/3), //季度
			"S"  : this.getMilliseconds()             //毫秒
		};
		if(/(y+)/.test(fmt))
			fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
		for(var k in o)
			if(new RegExp("("+ k +")").test(fmt))
		fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
		return fmt;
	}
	var form
	var app=new Vue({
		el: '#content',
		data: {
			curUserId:'',
			inputAccount:'',// 输入的帐号信息
			selMatchId: '',// 选中的比赛id
			selGradeId: '',// 选中的组别ID
			selZoneId: '',//  选中的赛区ID
			selState: '', //  选中的报名状态
			signUpList:[],//报名数据
			teamList:[],
			gradeList:[],
			matchList:[],
			zoneList:[],
			saichengList:[],
			list:[],
			pageNo: 1,
			pageSize: 50,
			status:['审核','待审核' ,'通过', '不通过'],
			participate:['审核','参赛' ,'弃权' ],
			cols: [ //表头
				{field: 'id', title: '序号', width: 80},
				
				{field: 'operating', title: '操作', width: 135 },
				{field: 'status', title: '审核状态', width: 135 },
				
				{field: 'state', title: '组队状态', width: 135 },
				{field: 'player', title: '队员', width: 135 },
				
				{field: 'signupId', title: '团队ID', width: 80},
				{field: 'username', title: '姓名', width: 110},
				{field: 'account', title: '账号', width: 110},
				{field: 'project', title: '赛项', width: 110},
				{field: 'division', title: '赛区', width: 110},
				{field: 'saicheng', title: '晋级状态', width: 110},
				{field: 'group', title: '组别', width: 110},
				{field: 'teamName', title: '团队名称', width: 110},
				{field: 'teacher', title: '指导老师', width: 110},
				{field: 'school', title: '学校/机构', width: 135},
				
				
				{field: 'isEnter', title: '是否参赛', width: 135 },
				

			]
		},
		mounted: function() {
			var vm = this
			layui.use('form', function () {
				form=layui.form;
				vm.form = layui.form;
				vm.form.on('submit(search)', function (data) {
					var field = data.field
					vm.selMatchId = field.selMatchId
					vm.selGradeId = field.selGradeId
					vm.selZoneId = field.selZoneId
					vm.selState = field.selState
					vm.inputAccount=field.number;
					if(vm.inputAccount == ''){
						vm.curUserId=''
						vm.loadSignUpList();
					}else {
						vm.loadAccount();
					}
					setTimeout(function(){
						form.render()
					},1000)

				})
				vm.form.on('select(matchStatusChange)', function (data) {
					vm.$refs.search.click()
				})
				vm.form.on('select(matchSelChange)', function (data) {
					vm.$refs.search.click()
				})
				vm.form.on('select(zoneSelChange)', function (data) {
					vm.$refs.search.click()
				})
				vm.form.on('select(gradeSelChange)', function (data) {
					vm.$refs.search.click()
				})
				vm.form.on('select(stateSelChange)', function (data) {
					vm.$refs.search.click()
				})
			});
		},
		methods:{
			opentab:function(name,url){
				//单击事件
				console.log(name)
				console.log(url)
				xadmin.add_tab(name,url)
			},
			delet1:function(myid){
				 //删除组队信息
				 if (confirm("是否删除改组队信息？")){
					 delTeam(myid,function(data){
                  alert("删除成功！")
									location.reload()
					 })
				 }
			},
			review:function(varUserId,varTeamId,projectid,project,status){
				 if (status==0||status=='0'){
					 alert("该队伍在还未组队成功，不可以审核！")
					 return false
				 }
				 localStorage.project=project

					getMatchEntiry(projectid,function(data){
						   var endtime=''
							 var chedulesList=data.chedulesList
							 for (i=0;i<chedulesList.length;i++){
										if (chedulesList[i].schedule.scheduleName=='初赛'){
											endtime=new Date(chedulesList[i].schedule.endTime).Format("yyyy-MM-dd hh:mm:ss")
										}
									}
									var cday=new Date().Format("yyyy-MM-dd hh:mm:ss")
									if (cday<endtime){
											xadmin.open('审核','review.html?userId='+varUserId+"&&teamId="+varTeamId,600,400);
											return false
									}
									else {
										  alert("已经超过初赛报名审核时间,无法完成审核!")
											return false
									}




						},function(status,message){
						})
				// for(var i=0; i<this.signUpList.records.length; ++i){

				// }

			},
			changeSel:function(event){
				console.log(event);
			},
			showMemberList:function(varTeamId,saicheng,matchId){
				// alert(matchId)

				localStorage.mysaicheng=saicheng
				var tmList=[]
				for(var i=0; i<this.teamList.length; ++i){
					if(this.teamList[i].signupId == varTeamId)
						tmList.push(this.teamList[i])
				}
				// alert(JSON.stringify(tmList))
				var varTool = fun_tool();
				var varKey="playerinfomation";
				varTool.setObject(varKey,tmList);
				getMatchEntiry(matchId,function(data){
           chedulesList=data.chedulesList
					 localStorage.mysxid=matchId
					 localStorage.mysaichenglist=JSON.stringify(chedulesList)
					 	parent.xadmin.open('队员信息','playerInformation.html?key='+varKey,1300,600)
				})

			},
			loadAccount:function(){
				var varParam={
					eq:{
						userName:this.inputAccount
					}
				}
				AccountqueryList(varParam,function(data){
					if(data != null && data.length > 0){
						app.curUserId=data[0].id;
					}
					app.loadSignUpList();

				})
			},
			loadTeamList:function(){
				var queryTeam={
					in:{
						attrName:"signup_id",
						data:[]
					}
				}
				for (var i = 0; i < this.signUpList.records.length; ++i) {
			        queryTeam.in.data.push(this.signUpList.records[i].id);
			    }
			    if(queryTeam.in.data.length == 0){
			    	return;
			    }
			TeamUserinfoViewqueryList(queryTeam,function(data){

					app.teamList=data;
					console.log(JSON.stringify(data))
					app.initList();
				},function(status,message){
				})
			},
			loadSignUpList:function(){
				this.list = [];
				var vm = this
				var queryData = {
				    page:{
				        current: vm.pageNo, //当前页数
				        size: vm.pageSize   //每页长度
				    },
				    cond:{ //条件申述
				        eq:{ // 多条件对象
				        	zoneId:this.selZoneId==''?null:this.selZoneId,
				        	groupId:this.selGradeId==''?null:this.selGradeId,
				        	matchId:this.selMatchId==''?null:this.selMatchId,
				        	state:this.selState==''?null:this.selState,
				        	userId:this.curUserId==''?null:this.curUserId
	                    }
				    }
				};
				if(this.selZoneId > 0){
					queryData.cond.eq.zoneId = this.selZoneId;
				}
				if(this.selGradeId > 0){
					queryData.cond.eq.groupId=this.selGradeId;
				}
				if(this.selState > 0){
					queryData.cond.eq.state=this.selState;
				}
				if(this.selMatchId > 0){
					queryData.cond.eq.matchId=this.selMatchId;
				}
				SignupPageList(queryData,function(data){

					vm.signUpList=data
				  // alert(JSON.stringify(vm.signUpList))
					vm.loadTeamList();
					app.init();
				},function(status,message){
				});
			},
			loadGradeList:function(){
				GradequeryList({},function(data){
					app.gradeList=data


				},function(status,message){
				})
			},
			loadMatchList:function(){
				TmatchqueryList({},function(data){
					// alert(JSON.stringify(data))
					app.matchList=data
					// form.render("select")
				},function(status,message){
				})
			},
			loadZoneList:function(){
				var funTool = fun_tool();
				app.zoneList=funTool.getAdminZoneIds();
			},
			getTeamLearInfo:function(varTeamId,varMemberType){
				for(var i=0; i<this.teamList.length; ++i){
					if(this.teamList[i].roleType == varMemberType && this.teamList[i].signupId==varTeamId){
						return this.teamList[i];
					}
				}
				return null;
			},
			getMathItemFromMem:function(varMatchId){
				for(var i=0; i<this.matchList.length; ++i){
					if(this.matchList[i].id == varMatchId){
						return this.matchList[i];
					}
				}
				return null;
			},
			getZoneFromMem:function(varZoneId){
				for(var i=0; i<this.zoneList.length; ++i){
					if(varZoneId == this.zoneList[i].id){
						return this.zoneList[i]
					}
				}
				return null;
			},
			getGradeFromMem:function(varGradeId){
				for(var i=0; i<this.gradeList.length; ++i){
					if(varGradeId == this.gradeList[i].id){
						return this.gradeList[i];
					}
				}
				return null;
			},
			getsaichenginfo:function(id){
				for(var i=0; i<this.saichengList.length; ++i){
					if(id == this.saichengList[i].id){
						return this.saichengList[i];
					}
				}
				return null;
			},
			initList:function(){
				this.list = [];
				 console.log(JSON.stringify(this.signUpList.records))
				for(var i=0 ; i<this.signUpList.records.length; ++i){
					var listItem={};
					listItem.id=i+(this.signUpList.current-1)*this.signUpList.size;
					var teamLeader = this.getTeamLearInfo(this.signUpList.records[i].id,2);
					var teamTeacher = this.getTeamLearInfo(this.signUpList.records[i].id,1) || {};
					var matchInfo = this.getMathItemFromMem(this.signUpList.records[i].matchId)
					var zoneInfo = this.getZoneFromMem(this.signUpList.records[i].zoneId)
					var gradeInfo = this.getGradeFromMem(this.signUpList.records[i].groupId)
					var saichenginfo = this.getsaichenginfo(this.signUpList.records[i].scheduleId)
					if (saichenginfo!=null){
				   listItem.saicheng=saichenginfo.scheduleName
					}

					if(teamLeader != null){
						listItem.signupId = this.signUpList.records[i].id
						listItem.userId=this.signUpList.records[i].userId
						listItem.username=teamLeader.memberName;
						listItem.matchId=this.signUpList.records[i].matchId

						listItem.account=teamLeader.phone;
						if(matchInfo != null){
							listItem.project=matchInfo.theme;
							listItem.projectid=this.signUpList.records[i].matchId
						}
						if(zoneInfo != null){
							listItem.division=zoneInfo.zoneName;
						}
						listItem.group=gradeInfo.gradeName
						listItem.teamName=teamLeader.teamName
						listItem.teacher=teamTeacher.memberName;
						listItem.school = teamLeader.schoolName;
						listItem.status = this.signUpList.records[i].state
						listItem.message=this.signUpList.records[i].message
					}
					console.log(zoneInfo)
					if(zoneInfo != null){
					this.list.push(listItem)
				}
				}
				  console.log(JSON.stringify(this.list.length))
				this.list=this.list.reverse()
				// alert(JSON.stringify(this.list))
			},
			getsaicheng:function(){

				SchedulequeryList({},function(data){
					// alert(JSON.stringify(data))
					app.saichengList=data
					// form.render("select")
				},function(status,message){
				})
			},
			getData:function(){
				this.list =  []
				this.loadZoneList();
				this.loadMatchList();
				this.loadGradeList();
				this.getsaicheng();
				this.loadSignUpList();
				setTimeout(function(){
					form.render()
				},1000)
				//this.loadTeamList();
				//this.initList();
				//this.init();

			},
			init:function() {
				var that = this
				// alert(JSON.stringify(that.list))
				!layui.laypage && layui.use(['laypage'], function () {
					var laypage = layui.laypage;
					//执行一个laypage实例
					laypage.render({
						elem: 'test1', //注意，这里的 test1 是 ID，不用加 # 号
						limit: that.pageSize,
						count: app.signUpList.total, //数据总数，从服务端得到
						jump: function (data, first) {
							if (first) return
							that.pageNo = data.curr
							that.loadSignUpList()
						}
					});
				})
			}
		}
	})
	window.onload=function(){
		app.getData()
	}
</script>
<script src="./js/jquery.min.js"></script>
<script>
// $(function () {
// 	layui.use(['form'], function () {
// 		var form = layui.form
// 		// layer.msg('玩命卖萌中', function(){
// 		//   //关闭后的操作
// 		//   });
// 		//监听提交
// 		form.on('submit(sreach)', function (data) {
// 			console.log(data)
// 			// layer.msg(JSON.stringify(data.field), function () {
// 			// location.href = 'index.html'
// 			// })
// 			return false
// 		})
// 	})
// })
</script>
</html>
